//
//  Method1View.swift
//  corner_shadow
//
//  Created by 李煜 on 2024/5/13.
//https://blog.csdn.net/feosun/article/details/86657330
//https://blog.csdn.net/liushuo19920327/article/details/123006034

import UIKit

class Method1View: UIView {
    let contentView: UIView = UIView()
    override init(frame: CGRect) {
        super.init(frame: frame)
        //方式一: contentView设置圆角+contentView底部添加一个layer设置圆角和阴影
        addSubview(contentView)
        contentView.frame = bounds
        contentView.backgroundColor = .white

        contentView.layer.cornerRadius = 30
        contentView.layer.masksToBounds = true
        
        // 圆角视图下面添加一个layer
        let subLayer = CALayer()
        subLayer.frame = contentView.frame
        subLayer.cornerRadius = 30
        subLayer.masksToBounds = false
        subLayer.backgroundColor = UIColor.white.cgColor
        #warning("layer必须提供backgroundColor才有效")
        subLayer.shadowColor = UIColor.black.cgColor
        subLayer.shadowOffset = CGSize(width: 2, height: 2)
        subLayer.shadowOpacity = 0.5
        subLayer.shadowRadius = 2

        layer.insertSublayer(subLayer, below: contentView.layer)
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
